﻿/// <reference name="MicrosoftAjax.js"/>
/// <reference path="aaagctrl.js"/>
/// <reference path="SBT.js"/>
/// <reference path="ProcessItem.js"/>
/// <reference path="Services/ProcessList.svc"/>

Type.registerNamespace("_05_NameScopes");

_05_NameScopes.Manager = function(element) {
    _05_NameScopes.Manager.initializeBase(this, [element]);
}

_05_NameScopes.Manager.prototype = {
    initialize: function() {
        _05_NameScopes.Manager.callBaseMethod(this, 'initialize');
        
        // Add custom initialization here
    },
    dispose: function() {        
        //Add custom dispose actions here
        _05_NameScopes.Manager.callBaseMethod(this, 'dispose');
    },
    onSilverlightLoaded: function(plugin, args)
    {
        var downloader = plugin.createObject("downloader");
        downloader.addEventListener("completed", Function.createDelegate(this, this.onDownloaderCompleted));
        downloader.open("GET", "Templates.zip");
        downloader.send();
    },
    onDownloaderCompleted : function (downloader, args)
    {
        var plugin = this.get_plugin();
        var pluginContent = plugin.Content;
        
        var btnDown = downloader.getResponseText("btnDown.xaml");
        var btnEnter = downloader.getResponseText("btnEnter.xaml");
        var btnLeave = downloader.getResponseText("btnLeave.xaml");
        var btnUp = downloader.getResponseText("btnUp.xaml");
        
        var itemTpl = downloader.getResponseText("ProcessItem.xaml");
        
        var upArrow = $create(SBT.Button, {element:pluginContent.findName("btnUp"), 
                        plugin:plugin,
                        mouseDownTemplate:btnDown,
                        mouseUpTemplate:btnUp,
                        mouseEnterTemplate:btnEnter,
                        mouseLeaveTemplate:btnLeave
                       },null,null,null);
       
        var downArrow = $create(SBT.Button, {element:pluginContent.findName("btnDown"), 
                        plugin:plugin,
                        mouseDownTemplate:btnDown,
                        mouseUpTemplate:btnUp,
                        mouseEnterTemplate:btnEnter,
                        mouseLeaveTemplate:btnLeave
                        },null,null,null);
        var scroller = new SBT.VerticalPageFlipScroller();
        scroller.set_bottomButton(downArrow);
        scroller.set_topButton(upArrow);
        scroller.set_stepSize(30);
        scroller.set_animDuration("00:00:00.1500000");
        
        this._stackProcesses = $create(SBT.StackPanel,{plugin:plugin,element:pluginContent.findName("procList_content")},null,null,null);
        $create(SBT.ScrollContainer,{plugin:plugin,element:pluginContent.findName("procList_container"),content:this._stackProcesses,scroller:scroller},null,null,null);
        
        var t = this;
        demos.sbt.com.processlist.GetProcesses(
            function(result)
            {
                var panel = t._stackProcesses.get_element();
                for(var i=0;i<result.length;i++)
                {
                    var item = pluginContent.createFromXaml(itemTpl,true);
                    panel.Children.Add(item);
                    $create(_05_NameScopes.ProcessItem,{plugin:plugin,element:item,data:result[i]},null,null,null);
                }
                t._stackProcesses.invalidateLayout();
            },
            function(error)
            {
            },null);
    }
}
_05_NameScopes.Manager.registerClass('_05_NameScopes.Manager', SBT.SLManager);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
